<?php

function formatDate ($dbDate,$type)
{
	if ($dbDate == "0000-00-00" || $dbDate == "") {
		return "";
	}
	list($year,$month,$day) = sscanf($dbDate,"%d-%d-%d");
	if ($type == "long") {
		$dateF = adodb_date("l, F j, Y", adodb_mktime(0,0,0,$month,$day,$year));
	} elseif ($type == "year_first") {
		$month = str_pad($month, 2, "0", STR_PAD_LEFT);
		$day   = str_pad($day,   2, "0", STR_PAD_LEFT);
		$dateF = "$year-$month-$day";
	} else {
		$dateF = "$month/$day/$year";
	}
	return $dateF;
}

function formatName ($first, $middle, $last, $suffix, $nick, $items)
{
	$formatName = "";
	if (strpos($items, "f") !== FALSE && $first != "") {
		$formatName .= htmlentities($first,NULL,"UTF-8")." ";  }
	if (strpos($items, "n") !== FALSE && $nick != "") {
		$formatName .= htmlentities($nick,NULL,"UTF-8")." ";  }
	if (strpos($items, "m") !== FALSE && $middle != "") {
		$formatName .= htmlentities($middle,NULL,"UTF-8")." ";  }
	if (strpos($items, "l") !== FALSE && $last != "") {
		$formatName .= htmlentities($last,NULL,"UTF-8");  }
	if (strpos($items, "s") !== FALSE && $suffix != "") {
		$formatName .= ", ".htmlentities($suffix,NULL,"UTF-8");  }
	//print("Formatted name: $formatName<br />\n");
	return $formatName;
}

function ChkIsMobile ()
{
	// See example below http://php.net/manual/en/function.get-browser.php
	// but decided too complicated
	$agent = strtolower(isset($agent) ? $agent : $_SERVER['HTTP_USER_AGENT']);
	//print("Agent is: " . $agent);
	if (preg_match("/iphone/", $agent)) {
		return true;
	} elseif (preg_match("/ipod/", $agent)) {
		return true;
	} elseif (preg_match("/android/", $agent)) {
		return true;
	} elseif (preg_match("/blackberry/", $agent)) {
		return true;
	} elseif (preg_match("/palm/", $agent)) {
		return true;
	} elseif (preg_match("/webos/", $agent)) {
		return true;
	} elseif (preg_match("/windows phone os 7/", $agent)) {  //PocketPC
		return true;
	} elseif (preg_match("/ppc/", $agent)) {  //PocketPC
		return true;
	} else {
		return false;
	}
}

?>